package com.yanjiali.controller;

import com.yanjiali.model.R;
import com.yanjiali.model.req.RecordPersonalHistoricalRecordsReq;
import com.yanjiali.model.resp.ObtainTheHistoricalRecordsTo5ThroughTheUserIdResp;
import com.yanjiali.model.resp.RecordPersonalHistoricalRecordsResq;
import com.yanjiali.model.resp.SearchHistoryByTitleResp;
import com.yanjiali.service.HistoryService;
import com.yanjiali.vo.HistoricalRecordYearVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Package: com.yanjiali.controller
 * @Author: yanjiali
 * @Created: 2025/4/19 15:09
 */
@Api("历史记录控制器")
@RestController
@RequestMapping("/v1/historys")
public class HistoryController {

    @Autowired
    HistoryService historyService;

    @PostMapping("/recordPersonal")
    @ApiOperation("记录个人历史记录接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "recordPersonalHistoricalRecordsReq", value = "recordPersonalHistoricalRecordsReq")
    })
    public R<RecordPersonalHistoricalRecordsResq> recordPersonalHistoricalRecords(@RequestBody RecordPersonalHistoricalRecordsReq recordPersonalHistoricalRecordsReq) {
        return historyService.recordPersonalHistoricalRecords(recordPersonalHistoricalRecordsReq);
    }

    @GetMapping("/getHistoryRecordTo5")
    @ApiOperation("获取用户的历史记录前五个接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "", value = "")
    })
    public R<ObtainTheHistoricalRecordsTo5ThroughTheUserIdResp> obtainTheHistoricalRecordsTo5ThroughTheUserId() {
        return historyService.obtainTheHistoricalRecordsTo5ThroughTheUserId();
    }

    @GetMapping("/getHistoryRecordToCurrentYear")
    @ApiOperation("获取当前登录用户当前年份的所有历史记录")
    public R<HistoricalRecordYearVO> obtainTheCurrentYearsHistoricalRecords() {
        return historyService.obtainTheCurrentYearsHistoricalRecords();
    }

    @GetMapping("/searchHistoryByTitle")
    @ApiOperation("通过历史记录标题搜索对应历史记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "历史记录标题")
    })
    public R<SearchHistoryByTitleResp> searchHistoryByTitle(@RequestParam String title) {
        return historyService.searchHistoryByTitle(title);
    }

    @PostMapping("/deleteInBatches")
    @ApiOperation("批量删除对应用户id集合的历史记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "对应需要批量删除的id集合")
    })
    public R deleteInBatches(@RequestBody List<Long> ids) {
        return historyService.deleteInBatches(ids);
    }

    @GetMapping("/deleteOneByOne")
    @ApiOperation("单个删除对应用户历史记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对应历史记录id")
    })
    public R deleteOneByOne(@RequestParam Long id) {
        return historyService.deleteOneByOne(id);
    }

    @GetMapping("/deleteAll")
    @ApiOperation("删除所有用户记录")
    public R deleteAll() {
        return historyService.deleteAll();
    }
}
